﻿using MahApps.Metro.Controls;
using System.Windows;
using FolderTag.DB;
using MahApps.Metro.Controls.Dialogs;
using FolderTag.Core;
using FolderTag.ExtendView.Tools;

namespace FolderTag
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        public MetroDialogSettings MetroDialogSettings = new MetroDialogSettings()
        {
            AffirmativeButtonText = "确认",
            NegativeButtonText = "取消",
        };
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ToggleSwitch_ShowAllFile.DataContext = SystemConfig.Config;
            bool openSuccess = DBHelper.SQL_R.Connection.State == System.Data.ConnectionState.Open;
            if (openSuccess)
                DBHelper.BackDb();
            Title = $"标签化目录管理工具 Version：1.1 数据读取[{(openSuccess ? "正常" : "异常")}]";
        }

        /// <summary>
        /// 窗口关闭事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            DBHelper.Close();
        }


        private void ToggleSwitch_ShowAllFile_Toggled(object sender, RoutedEventArgs e)
        {
            SystemConfig.Save();
            Ctl_FolderControl.LoadPath("cur");
        }

        private ToolsMainWindow _ToolsMainWindow = null;

        /// <summary>
        /// 窗口顶部按钮（工具）
        /// 一些自己写的小工具，例如Base64编码，UrlCode编码等
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WindowBtn_Tools(object sender, RoutedEventArgs e)
        {
            if (_ToolsMainWindow == null || !_ToolsMainWindow.IsVisible)
            {
                _ToolsMainWindow = new ToolsMainWindow();
                _ToolsMainWindow.Show();
            }
        }
    }
}
